function [ROI ROI1]=rangeofinterest(xpeak,ypeak,radial_cloud,rectangle_FWHM0,x_min,y_min)
%define all cloud region,ie.find range of interest
% x0num=find(xpeak==0);
% y0num=find(ypeak==0);
% radial0num=find(radial_cloud==0);
% if x0num>=1&y0num>=1&radial0num>=1
%     xpeak(find(xpeak==0))=[];
%     ypeak(find(ypeak==0))=[];
%     radial_cloud(find(radial_cloud==0))=[];
%     xpeak=xpeak(:);
%     ypeak=ypeak(:);
%     radial_cloud=radial_cloud(:);
% end

rectangle_width_min=500;
rectangle_height_min=450;
rectangle_width_max=650;
rectangle_height_max=600;
if length(xpeak)==1
    xmin=xpeak(1,1)-radial_cloud(1,1)-rectangle_FWHM0;
    ymin=ypeak(1,1)-radial_cloud(1,1)-rectangle_FWHM0;
    rectangle_width=2*(radial_cloud(1,1)+rectangle_FWHM0);
    rectangle_height=rectangle_width;
    while rectangle_width<rectangle_width_min
        rectangle_FWHM0=rectangle_FWHM0+30;
        xmin=xpeak(1,1)-radial_cloud(1,1)-rectangle_FWHM0;
        rectangle_width=2*(radial_cloud(1,1)+rectangle_FWHM0);
    end
    rectangle_FWHM=rectangle_FWHM0;
     while rectangle_height<rectangle_height_min
        rectangle_FWHM=rectangle_FWHM+30;
        ymin=ypeak(1,1)-radial_cloud(1,1)-rectangle_FWHM;
        rectangle_height=2*(radial_cloud(1,1)+rectangle_FWHM);
    end
    %              centerx=535;centery=506;
else
    [min_xpeak,min_positionx]=min(xpeak);
    min_xpeak_radial=radial_cloud(min_positionx,1);
    [min_ypeak,min_positiony]=min(ypeak);
    min_ypeak_radial=radial_cloud(min_positiony,1);
    [max_xpeak,max_positionx]=max(xpeak);
    max_xpeak_radial=radial_cloud(max_positionx,1);
    [max_ypeak,max_positiony]=max(ypeak);
    max_ypeak_radial=radial_cloud(max_positiony,1);
    xmin0=min_xpeak-min_xpeak_radial;
    ymin0=min_ypeak-min_ypeak_radial;
    xmax0=max_xpeak+max_xpeak_radial;
    ymax0=max_ypeak+max_ypeak_radial;
    xmin=xmin0-rectangle_FWHM0;
    ymin=ymin0-rectangle_FWHM0;
    rectangle_width=(xmax0-xmin0)+2*rectangle_FWHM0;
    rectangle_height=(ymax0-ymin0)+2*rectangle_FWHM0;
    
    if xmin<x_min;xmin=x_min;end
    if ymin<y_min;ymin=y_min;end
    
    
    rectangle_FWHM=rectangle_FWHM0;
    while (rectangle_width>rectangle_width_max)
        rectangle_FWHM=rectangle_FWHM-40;
        xmin=xmin0-rectangle_FWHM;
        rectangle_width=(xmax0-xmin0)+2*rectangle_FWHM;
        if rectangle_FWHM<=50
           break; 
        end
    end
    rectangle_FWHM=rectangle_FWHM0;
    while (rectangle_height>rectangle_height_max)
        rectangle_FWHM=rectangle_FWHM-30;
        ymin=ymin0-rectangle_FWHM;
        rectangle_height=(ymax0-ymin0)+2*rectangle_FWHM;
        if rectangle_FWHM<=50
           break; 
        end
    end
    
end
%              x_min=80;y_min=130;

if xmin<x_min;xmin=x_min;end
if ymin<y_min;ymin=y_min;end
% if rectangle_width<550;rectangle_width=550;end
% if rectangle_height<500;rectangle_height=500;end

%define range of ROI1=[xmin1 ymin1 rectangle_width1 rectangle_height1]
min_limit=130;min_move=30;
if xmin<min_limit
    xmin1=xmin-min_move;
else
    xmin1=100;
end
if ymin<min_limit
    ymin1=ymin-min_move;
else
    ymin1=100;
end
rectangle_width1=800;
rectangle_height1=rectangle_width1;
ROI=[xmin ymin rectangle_width rectangle_height];
ROI1=[xmin1,ymin1,rectangle_width1,rectangle_height1];

             